<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
    <style>
        .layui-input{
            width: 200px;
        }
    </style>
</head>
<body>


<div id="addBookDiv" >
    <form class="layui-form" id="addForm" lay-filter="addForm">
        <div class="layui-form-item">
            <label class="layui-form-label">当前密码</label>
            <div class="layui-input-inline">
                <input type="password"  name="password"   required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="newPwd" id="StorePassword" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">确认新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="nnewPwd" id="newStorePassword" required lay-verify="required" placeholder="请再次输入新密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn"  lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer','jquery'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        //formdemo表单提交事件----》提交按钮中   lay-filter的值







        form.on('submit(formDemo)',function (data) {
            if(data.field.password == ${sessionScope.staff.password}){
                var p1=$("#StorePassword").val();
                var p2=$("#newStorePassword").val();
                if (p1 == p2){
                    $.ajax({
                        type:"post"
                        ,url:"${pageContext.request.contextPath}/staff/uppassword"
                        ,data:{"password":data.field.newPwd}
                        ,dataType:'json'
                        ,success: function (result) {
                            //alert(result!=null);
                            if (result.code == 200 ){
                                layer.closeAll();
                                alert("密码修改成功");
                                location.href = '/bookstore/login.jsp';
                            }else{
                                layer.msg(result.msg);
                            }
                        }
                    })
                }else {
                    alert("两次输入的密码不一致");
                }
            }else {
                alert("原密码输入错误,无法修改");
            }

            return false;//阻止表单跳转，如果需要表单跳转，去掉这条语句
        })
    });
</script>
</body>
</html>
